package canss.webservice.controls;

import org.apache.beehive.controls.api.bean.Control;
import org.apache.beehive.controls.api.bean.ControlImplementation;

import canss.webservice.model.Linkage;

import weblogic.jdbc.SQLExceptionWrapper;

import java.io.Serializable;

@ControlImplementation
public class LinkageControlImpl implements LinkageControl, Serializable
{
	private static final long serialVersionUID = -161250969227113927L;
	@Control
	private BusinessSystemDB businesssystemDB;
	
	public Boolean resetLinkage() throws SQLExceptionWrapper
	{
		int ret = businesssystemDB.ResetEntireLinkages();
		return ret>0;
	}
	
	public Boolean addLinkage(String _tblPID_pid, String _tblCID_cid, String _ContId) throws SQLExceptionWrapper
	{
		int ret;
		try
		{
			ret = businesssystemDB.DeleteDuplicatedCID(_tblPID_pid, _tblCID_cid);
			ret = businesssystemDB.AddLinkage(_tblPID_pid, _tblCID_cid, _ContId);
			return ret>0;
		} catch (Exception e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	public Linkage[] getEntireLinkage() throws SQLExceptionWrapper
	{
		return businesssystemDB.GetEntireLinkage();
	}
	
	public String[] getLinkageByCONTID(String _tblPID_pid, String _ContId) throws SQLExceptionWrapper
	{
		return businesssystemDB.GetLinkageByCONTID(_tblPID_pid, _ContId);
	}
}